{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Orca.Prim.CsoundPP
-- Copyright   :  (c) Stephen Tetley 2013
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Csound pretty print functions.
--
-- Precedence has been adopted from C99.
--
--------------------------------------------------------------------------------

module Orca.Prim.CsoundPP
  (
    
    unparse

  -- ** Precedence 15
  , bitwiseNotU
  , logicalNotU
  , negateU

  -- ** Precedence 13
  , multiplyB
  , divideB
  , moduloB

  -- ** Precedence 12
  , addB
  , subtractB

  -- ** Precedence 10
  , lessThanB
  , greaterThanB
  , lessThanEqB
  , greaterThanEqB

  -- ** Precedence 9
  , equalB
  , notEqualB

  -- ** Precedence 8
  , bitwiseAndB

  -- ** Precedence 7
  , bitwiseOrB


  -- ** Precedence 5
  , logicalAndB

  -- ** Precedence 4
  , logicalOrB

    
  ) where



import Text.PrettyExprHPJ                   -- package: pretty-expr-hpj

import Text.PrettyPrint.HughesPJ            -- pacakge: pretty

-- | Run an unparser for C-like language expressions.
-- 
-- C99 has maximum precedence of 16.
--
unparse :: DocE -> Doc
unparse = unparser $ makeUnparser 16


--------------------------------------------------------------------------------
-- Precedence 15


-- | Bitwise not.
-- 
-- > ~ (prefix 15)
--
bitwiseNotU             :: DocE -> DocE
bitwiseNotU             = Unary $ prefix 15 NoSpace "~"


-- | Logical not.
-- 
-- > ! (prefix 15)
--
logicalNotU             :: DocE -> DocE
logicalNotU             = Unary $ prefix 15 NoSpace "!"

-- | Arithmetic negation.
-- 
-- > - (prefix 15)
--
negateU                :: DocE -> DocE
negateU                = Unary $ prefix 15 NoSpace "-"

--------------------------------------------------------------------------------
-- Precedence 13

-- | Multiplication.
-- 
-- > * (infixl 13)
--
multiplyB               :: DocE -> DocE -> DocE
multiplyB               = Binary $ infixL 13 NoSpace "*"

-- | Division.
-- 
-- > / (infixl 13)
--
divideB                 :: DocE -> DocE -> DocE
divideB                 = Binary $ infixL 13 NoSpace "/"



-- | Modulus.
-- 
-- > % (infixl 13)
--
moduloB                 :: DocE -> DocE -> DocE
moduloB                 = Binary $ infixL 13 NoSpace "%"



--------------------------------------------------------------------------------
-- Precedence 12

-- | Addition.
-- 
-- > + (infixl 12)
--
addB                    :: DocE -> DocE -> DocE
addB                    = Binary $ infixL 12 NoSpace "+"

-- | Subtraction.
-- 
-- > - (infixl 12)
--
subtractB               :: DocE -> DocE -> DocE
subtractB              = Binary $ infixL 12 NoSpace "-"


--------------------------------------------------------------------------------
-- Precedence 10

-- | Less than.
-- 
-- > < (infixl 10)
--
lessThanB               :: DocE -> DocE -> DocE
lessThanB               = Binary $ infixL 10 Space "<"


-- | Less than or equal.
-- 
-- > <= (infixl 10)
--
lessThanEqB             :: DocE -> DocE -> DocE
lessThanEqB             = Binary $ infixL 10 Space "<="



-- | Greater than.
-- 
-- > > (infixl 10)
--
greaterThanB            :: DocE -> DocE -> DocE
greaterThanB            = Binary $ infixL 10 Space ">"


-- | Greater than or equal.
-- 
-- > >= (infixl 10)
--
greaterThanEqB          :: DocE -> DocE -> DocE
greaterThanEqB          = Binary $ infixL 10 Space ">="




--------------------------------------------------------------------------------
-- Precedence 9

-- | Equality.
-- 
-- > == (infixl 9)
--
equalB                  :: DocE -> DocE -> DocE
equalB                  = Binary $ infixL 9 Space "=="


-- | Inequality.
-- 
-- > != (infixl 9)
--
notEqualB               :: DocE -> DocE -> DocE
notEqualB               = Binary $ infixL 9 Space "!="


--------------------------------------------------------------------------------
-- Precedence 8


-- | Integer bitwise AND.
-- 
-- > & (infixl 8)
--
bitwiseAndB             :: DocE -> DocE -> DocE
bitwiseAndB             = Binary $ infixL 8 Space "&"



--------------------------------------------------------------------------------
-- Precedence 7


-- | Integer bitwise OR.
-- 
-- > | (infixl 7)
--
bitwiseOrB              :: DocE -> DocE -> DocE
bitwiseOrB              = Binary $ infixL 7 Space "|"


--------------------------------------------------------------------------------
-- Precedence 5

-- | Logical and.
-- 
-- > && (infixl 5)
--
logicalAndB             :: DocE -> DocE -> DocE
logicalAndB             = Binary $ infixL 5 Space "&&"


--------------------------------------------------------------------------------
-- Precedence 4

-- | Logical or.
-- 
-- > || (infixl 4)
--
logicalOrB              :: DocE -> DocE -> DocE
logicalOrB              = Binary $ infixL 4 Space "||"